package appconfig

import (
	"fmt"
	"github.com/fsnotify/fsnotify"
	"github.com/spf13/viper"
)

type AppConfig struct {
	Mysql
	Redis
	QiNiuYun
}

type Mysql struct {
	User     string
	Password string
	Host     string
	Port     int
	Database string
}

type Redis struct {
	Password string
	Host     string
	Port     int
}

type QiNiuYun struct {
	AccessKey string
	SecretKey string
	Bucket    string
}

var ConfigData AppConfig

func Init() {
	viper.SetConfigFile("../appconfig/config.yaml")
	viper.ReadInConfig()
	viper.Unmarshal(&ConfigData)
	fmt.Println(ConfigData)

	//热更新
	viper.OnConfigChange(func(e fsnotify.Event) {
		fmt.Println("Config file changed:", ConfigData)
	})
	viper.WatchConfig()
}
